package com.xqls.service.impl;

import com.xqls.bean.IntakeRealdataBean;
import com.xqls.dal.dao.IntakeRealdataDao;
import com.xqls.dal.model.IntakeRealdata;
import com.xqls.service.IntakeRealdataService;
import com.xqls.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class IntakeRealdataServiceImpl implements IntakeRealdataService{
	
	@Autowired private IntakeRealdataDao realdataDao;
	
	public boolean insertIntakeRealdata(IntakeRealdataBean intakeRealdataBeans){
				IntakeRealdata intakeRealdata=transfer(intakeRealdataBeans);
			return realdataDao.insertIntakeRealdata(intakeRealdata)>0;
	}
	public boolean updateIntakeRealdata(IntakeRealdataBean intakeRealdataBeans){
		IntakeRealdata intakeRealdata=transfer(intakeRealdataBeans);
		return realdataDao.updateIntakeRealdata(intakeRealdata)>0;
	}

	@Override
	public List<Map<String, Object>> selectByMap(Map<String, Object> map) {
		return realdataDao.selectByMap(map);
	}
	
	public IntakeRealdataBean queryByDeviceNo(String deviceNo){
		IntakeRealdata intakeRealdatas=realdataDao.selectByDeviceNo(deviceNo);
		if(intakeRealdatas==null) return  null;
		return transfer(intakeRealdatas);

	}
	@Override
	public IntakeRealdataBean queryByRealdataNo(Integer realdataNo) {
		return  transfer(realdataDao.queryByRealdataNo(realdataNo));
	}

	@Override
	public int deleteBydeviceNo(List device) {
		return realdataDao.deleteBydeviceNo(device);
	}

	public List<Map<String, Object>> queryAll(){
		return realdataDao.queryAll();
	}
	public IntakeRealdata selectByDeviceNo(String deviceNo){
		return realdataDao.selectByDeviceNo(deviceNo);
	}
	
	
	
	public IntakeRealdataBean transfer(IntakeRealdata intakeRealdata){
		IntakeRealdataBean realdataBean=new IntakeRealdataBean();
		realdataBean.setRealdataNo(intakeRealdata.getRealdataNo());
		realdataBean.setDeviceNo(intakeRealdata.getDeviceNo());
		realdataBean.setNetwork(intakeRealdata.getNetwork());
		realdataBean.setInstantaneousFlow(intakeRealdata.getInstantaneousFlow());
		realdataBean.setCumulativeFlow(intakeRealdata.getCumulativeFlow());
		realdataBean.setPowerSupply(intakeRealdata.getPowerSupply());
		return realdataBean;
	}
	
	public IntakeRealdata transfer(IntakeRealdataBean realdataBean){
		IntakeRealdata realdata=new IntakeRealdata();
		realdata.setRealdataNo(realdataBean.getRealdataNo());
		realdata.setDeviceNo(realdataBean.getDeviceNo());
		realdata.setNetwork(realdataBean.getNetwork());
		realdata.setInstantaneousFlow(realdataBean.getInstantaneousFlow());
		realdata.setCumulativeFlow(realdataBean.getCumulativeFlow());
		realdata.setPowerSupply(realdataBean.getPowerSupply());
		return realdata;
	}
	@Override
	public List<IntakeRealdataBean> selectListByMap(Map<String, Object> map) {
		return ObjectUtil.transferList(realdataDao.selectListByMap(map),IntakeRealdataBean.class);
	}

	@Override
	public List<IntakeRealdata> selectintake() {
		return realdataDao.selectintake();
	}

}
